package com.coinland.study.util;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.List;

/**
 * 类描述:  SharedPreferences常用于保存一些简单的数据
 * 创建人:  shenZ
 * 创建时间: 2020/4/15
 * 联系方式: 252079249@qq.com
 * 修改时间: 2020/4/15
 */
public class SharedPreUtils {

    /**
     * 保存int类型
     *
     * @param name
     * @param value
     */
    public static void saveInt(Context context, String name, int value) {
        SharedPreferences preferences = context.getSharedPreferences(Contant.SHARE_DATA, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();

        editor.putInt(name, value);
        editor.commit();
    }

    /**
     * 获取int类型
     *
     * @param name
     * @return
     */
    public static int getInt(Context context, String name) {
        SharedPreferences preferences = context.getSharedPreferences(Contant.SHARE_DATA, Activity.MODE_PRIVATE);
        return preferences.getInt(name, 0);

    }

    /**
     * 保存boolean类型
     *
     * @param name
     * @param value
     */
    public static void saveBoolean(Context context, String name, boolean value) {
        SharedPreferences preferences = context.getSharedPreferences(Contant.SHARE_DATA, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();

        editor.putBoolean(name, value);
        editor.commit();
    }

    /**
     * 获取boolean类型
     *
     * @param name
     * @return
     */
    public static boolean getBoolean(Context context, String name) {
        SharedPreferences preferences = context.getSharedPreferences(Contant.SHARE_DATA, Activity.MODE_PRIVATE);
        return preferences.getBoolean(name, false);

    }

    /**
     * 保存Stirng类型
     *
     * @param name
     * @param value
     */
    public static void saveString(Context context, String name, String value) {
        SharedPreferences preferences = context.getSharedPreferences(Contant.SHARE_DATA, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();

        editor.putString(name, value);
        editor.commit();
    }

    /**
     * 获取String类型
     *
     * @param name
     * @return
     */
    public static String getString(Context context, String name) {
        SharedPreferences preferences = context.getSharedPreferences(Contant.SHARE_DATA, Activity.MODE_PRIVATE);
        return preferences.getString(name, "");

    }

}
